home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / Alpha.5.96 folder / Tcl / SystemCode / filesets.tcl < prev    next >
Encoding:
Text File  |  1994-09-18  |  5.3 KB  |  175 lines  |  [TEXT/ALFA]

  1. #===============================================================================================
  2. # Create new filesets either by the "Utils:Add Fileset..." menu item. These 
  3. # filesets can be made permanent by "Utils:Dump Fileset..."ing the fileset 
  4. # to immediately below.
  5. #
  6. # Alpha calls two fileset-related routines, 'getCurrFileSet', and 
  7. # 'getFileSetNames'. Alpha will also attempt to set the variable 'currFileSet'
  8. # on occasion, but this isn't critical.
  9. #===============================================================================================
  10.  
  11. #===========================================================================
  12. # The filesets.
  13. #===========================================================================
  14.  
  15. # Build some filesets on the fly.
  16. catch {unset fileSets}
  17. catch {unset currFileSet}
  18. catch {set fileSets(HomeDir) [glob -t TEXT "$HOME:*"]}
  19. catch {set fileSets(Help) [glob -t TEXT   "$HOME:Help:*"]}
  20. catch {set fileSets(System) [glob -t TEXT "$HOME:Tcl:SystemCode:*.tcl"]}
  21. catch {set fileSets(User) [glob -t TEXT   "$HOME:Tcl:UserCode:*.tcl"]}
  22.  
  23. # Default curr fileset is the first one. Can be changed in 'userStartup.tcl'.
  24. set currFileSet [lindex [array names fileSets] 0]
  25.  
  26.  
  27. #===========================================================================
  28. # The support routines.
  29. #===========================================================================
  30. # Called from Alpha to get list of files for current file set.
  31. proc getCurrFileSet {} {
  32.     global fileSets
  33.     global currFileSet
  34.     return $fileSets($currFileSet)
  35. }
  36. # Called from Alpha to get names. The first name returned is taken to 
  37. # be the current fileset.
  38. proc getFileSetNames {} {
  39.     global fileSets
  40.     global currFileSet
  41.     set ind [lsearch [array names fileSets] $currFileSet]
  42.     if {$ind < 0} {set ind 0}
  43.     return [linsert [lsort [lreplace [array names fileSets] $ind $ind]] 0 $currFileSet]
  44. }
  45.  
  46.  
  47. # Keep 'sets' menu up to date.
  48. trace vdelete currFileSet w shadowCurrFileSet
  49. trace variable currFileSet w shadowCurrFileSet
  50. proc shadowCurrFileSet {nm1 nm2 op} {
  51.     global fileSets
  52.     global currFileSet
  53.     foreach name [array names fileSets] {
  54.         if {$name == $currFileSet} {
  55.             markMenuItem -m choose $name on
  56.         } else {
  57.             markMenuItem -m choose $name off
  58.         }
  59.     }
  60.     return $currFileSet
  61. }
  62.  
  63. # Called in response to user changing filesets from the fileset menu.
  64. proc changeFileSet {menu item} {
  65.     global currFileSet
  66.     
  67.     markMenuItem -m choose $currFileSet off
  68.     set currFileSet $item
  69.     markMenuItem -m choose $currFileSet on
  70. }
  71.  
  72.  
  73. #===========================================================================
  74. # Add fileset.
  75. #===========================================================================
  76. proc createFileset {} {
  77.     global fileSets
  78.     global currFileSet
  79.     
  80.     set name [getline "New fileset name:" ""]
  81.     if {![string length $name]} return
  82.     
  83.     set dir [string trim [get_directory] ":"]
  84.     if {![string length $dir]} return
  85.     
  86.     set filePat [getline "File pattern:" "*"]
  87.     if {![string length $filePat]} return
  88.     
  89.     set "fileSets($name)" [glob -t TEXT "$dir:$filePat"]
  90.     menu -n choose -m -p changeFileSet [lsort [array names fileSets]]
  91.     set currFileSet $name
  92.  
  93.     if {[askyesno "Save new fileset?"] == "yes"} {
  94.         addUserLine "set \"fileSets($name)\" \[glob -t TEXT  \{$dir:$filePat\}\]"
  95.     }
  96.     makeFilesetMenu
  97. }
  98.  
  99.  
  100. #===========================================================================
  101. # Dump fileset to current window. If you dump at the end of this file,
  102. # the fileset will be reloaded the next time you run Alpha.
  103. #===========================================================================
  104. proc dumpFileset {} {
  105.     global fileSets
  106.     global currFileSet
  107.     if {![catch {prompt "Fileset name:" $currFileSet} name]} {
  108.         insertText "set \"fileSets($name)\" \{\r"
  109.         foreach file "$fileSets($name)" {
  110.             insertText "\t\"$file\"\r"
  111.         }
  112.         insertText "\}\r"
  113.     }
  114. }
  115.  
  116.  
  117.  
  118. #================================================================================
  119. # Edit a file from a fileset via list dialogs (no mousing around).
  120. #================================================================================
  121. proc editFile {} {
  122.     global fileSets
  123.     
  124.     set fset [listpick -p {Fileset?} [lsort -ignore [array names fileSets]]]
  125.     if {[string length $fset]} {
  126.         foreach f $fileSets($fset) {
  127.             lappend disp [file tail $f]
  128.         }
  129.         set res [listpick -p {File?} [lsort -ignore $disp]]
  130.         if {[string length $res]} {
  131.             set ind [lsearch $fileSets($fset) \*$res]
  132.             edit [lindex $fileSets($fset) $ind]
  133.         }
  134.     }
  135. }
  136.  
  137.  
  138. #================================================================================
  139. # Create a heirarchical fileset menu that allows you 
  140. # to open any file in any fileset.
  141. #
  142. # Doesn't bother trying to specialcase names or pathnames that have
  143. # non-alphanumeric characters in them.
  144.  
  145. proc filesetProc {menu item} {
  146.     global fileSets
  147.     if {[set match [lsearch $fileSets($menu) *:$item]] >= 0} {
  148.         edit [lindex $fileSets($menu) $match]
  149.     }
  150. }    
  151.  
  152. proc makeFilesetMenu {} {
  153.     global fileSets fsetMenuName
  154.     foreach f [lsort [array names fileSets]] {
  155.         if {$f == "Help"} continue
  156.         set menu {}
  157.         foreach m $fileSets($f) {
  158.             lappend menu [file tail $m]
  159.         }
  160.         lappend sets [list menu -m -n $f -p filesetProc [lsort -i $menu]]
  161.     }
  162.     menu -m -n $fsetMenuName -p filesetProc [concat $sets {"(-" {menu -n Utilities {}}}]
  163.  
  164.     menu -n "Utilities" {
  165.         {menu -n choose -p changeFileSet {}}
  166.         "createFileset…"
  167.         "createThinkFileset…"
  168.         "dumpFileset…"
  169.         "/'editFile"
  170.         "(-"
  171.         "findTag"
  172.         "createTagFile"}
  173. }
  174.  
  175.